package org.ejc.tech.combo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class ComboMgr implements ComboConstants{

	private static ComboMgr instance;

	private List<Locale> localeListing;
	private Map<String, IComboHandler> registeredHandlers=new HashMap<String,IComboHandler>();
	
	
	private ComboMgr() {
		setup();
		registerHandlers();
		
	
	}

	public static ComboMgr getInstance(){
		if(instance==null){
			instance=new ComboMgr();
		}
		return instance;
	}
	
	private void setup(){
		localeListing=new ArrayList<Locale>();
		Locale localeEng = new Locale("en");
		Locale localeFr = new Locale("fr");
		localeListing.add(localeEng);
		localeListing.add(localeFr);
		//ok add all the locales from the database here !
	}
	
	void registerHandlers(){
		IComboHandler countryMgr=new CountryHandlerImpl();
		countryMgr.setupHandler(localeListing);
		
		IComboHandler accomodationTypeHandler=new AccomodationTypeHandlerImpl();
		accomodationTypeHandler.setupHandler(localeListing);
		
		IComboHandler additionalTypeHandler=new AdditionalInfoTypeHandlerImpl();
		additionalTypeHandler.setupHandler(localeListing);
		
		IComboHandler registrantTypeHandler=new RegistrantTypeHandlerImpl();
		registrantTypeHandler.setupHandler(localeListing);
		
		IComboHandler priceTypeHandler = new PriceTypeHandlerImpl();
		priceTypeHandler.setupHandler(localeListing);
		
		IComboHandler specialPriceTypeHandler = new PriceTypeSpecialPricesHandler();
		specialPriceTypeHandler.setupHandler(localeListing);
		
		registeredHandlers.put(ACCOMODATION_TYPE,accomodationTypeHandler);
		registeredHandlers.put(COUNTRY,countryMgr);
		registeredHandlers.put(ADDITIONAL_INFO,additionalTypeHandler);
		registeredHandlers.put(REGISTRANT_TYPE,registrantTypeHandler);
		registeredHandlers.put(PRICE_TYPE,priceTypeHandler);
		registeredHandlers.put(SPECIAL_PRICE_TYPE,specialPriceTypeHandler);
		
	}
	

	public Collection getComboContents(String comboName,Locale locale){
		return registeredHandlers.get(comboName).getLocalizedCollection(locale);
	}
}
